<?php
	header("Content-Type:text/html;charset=utf-8");

	include_once("conn.php");
	class delCate
	{
		public function delC()
		{	
			
			$sql="select cate_link.cid,link.lid from cate_link,link where cate_link.cid='".$_POST["cid2"]."' && link.lid=cate_link.lid";
			mysql_query("set names utf-8");
			$result=mysql_query($sql);
			while($cate_and_link=mysql_fetch_array($result))
			{
				$sql2="delete from link where lid='".$cate_and_link["lid"]."'";
				mysql_query($sql2);
			}
			$sql="select cate_link.cid,link.lid from cate_link,link where cate_link.cid='".$_POST["cid2"]."'";
			mysql_query("set names utf-8");
			$result2=mysql_query($sql);
			while($cate_and_link2=mysql_fetch_array($result2))
			{
				$sql3="delete from cate_link where cid='".$cate_and_link2["cid"]."' ";
				mysql_query($sql3);
			}

			$sql3="delete from cate_link where cid='".$cate_and_link["cid"]."' ";
			mysql_query($sql3);



			$sql="delete from category where cate_name='".$_POST["delcate_action"]."'";
			mysql_query($sql);

		}


	}
		
		
	class saveCate
	{
		public function saveC()
		{
			$sql="update category set cate_name='".$_POST["edit_cate_name"]."' where cate_name='".$_POST["delcate_action"]."' ";
			mysql_query("set names utf-8");
			mysql_query($sql);

		}
	}



	if($_POST["del_cate"]=="delete")
	{
		$obj=new delCate();
		$obj->delC();
		echo "分类删除成功";
		//header("Location:list_cate3.php");
		echo "<br>";
		echo "<a href='index.php'>返回</a>";

	}

	if($_POST["save_cate"]=="save")
	{
		$obj2=new saveCate();
		$obj2->saveC();
		echo "分类更新成功";
		//header("Location:list_cate3.php");
		echo "<br>";
		echo "<a href='list_cate3.php'>返回</a>";

	}

?>